package org.diy.redisson.config;

import org.diy.redisson.acpects.IdempotentAcpect;
import org.redisson.Redisson;
import org.redisson.RedissonReactive;
import org.redisson.api.RedissonClient;
import org.redisson.api.RedissonReactiveClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass({RedissonClient.class, Redisson.class,
        RedissonReactiveClient.class, RedissonReactive.class})
@EnableAutoConfiguration
public class IdempotentAutoConfig {
    @ConditionalOnBean({RedissonClient.class, Redisson.class,
            RedissonReactiveClient.class, RedissonReactive.class})
    @Bean
    public IdempotentAcpect idempotentAcpect(@Autowired RedissonClient client){
        return new IdempotentAcpect(client);
    }
}
